package com.lagou.xsq_springboot_rpc_consumer.factorybean;

import com.lagou.xsq_springboot_rpc_common.service.UserService;
import com.lagou.xsq_springboot_rpc_consumer.proxy.XsqProxyFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * @ClassName UserFactoryBean
 * @Description TODO
 * @Author xsq
 * @Date 2020/5/30 11:17
 **/
@Component
public class UserFactoryBean implements FactoryBean<UserService> {


    /**
     * 获取实例化对象
     *
     * @return
     * @throws Exception
     */
    @Override
    public UserService getObject() throws Exception {
        XsqProxyFactory proxyFactory = new XsqProxyFactory();
        return (UserService) proxyFactory.createProxy(this.getObjectType());
    }

    @Override
    public Class<?> getObjectType() {
        return UserService.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
